﻿using System;
using BizControl.Library.BusinessObjects.People;
using System.Security;
using Csla;
using BizControl.Resources;
using BizControl.Library.BusinessObjects.Models;

namespace BizControl.Library.Security
{
  internal class SecurityChecks
  {
    public static PersonBO GetCurrentUser()
    {
      PersonBO currentUser = (ApplicationContext.User as BizControlPrincipal).Person;
      if (currentUser == null) throw new SecurityException(ExceptionsMessages.UserIsNotLogged);
      return currentUser;
    }

    public static ModelBO GetCurrentModel()
    {
      var model = ((BizControlPrincipal)ApplicationContext.User).Model;
      if (null == model) throw new SecurityException(ExceptionsMessages.ModelIsNotSet);
      return model;
    }
  }
}
